package com.example.hbasespringbootdemo.controller;

import com.example.hbasespringbootdemo.model.City;
import com.example.hbasespringbootdemo.service.CityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
public class CityController {

    private Logger LOG = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private CityService cityService;

    @RequestMapping("/query")
    public City query(String row) {
        City city = cityService.query(row);
        return city;
    }

    @RequestMapping("/queryByRow")
    public List<City> queryByRow(String startRow, String endRow) {
        List<City> cityList = cityService.query(startRow, endRow);
        return cityList;
    }

    @RequestMapping("/save")
    public void save(String row) {
        try {
            cityService.saveOrUpdate(row);
        } catch (IOException e) {
            LOG.error("保存失败", e);
        }
    }
}
